<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="借阅人">
              <a-input placeholder="" v-model="queryParam.jyr"   ></a-input>
            </a-form-item>
          </a-col> 
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="操作类型">
              <a-select v-model="queryParam.czlx"    >
                
                <a-select-option  value="1">复印档案</a-select-option>
                <a-select-option  value="2">调用档案</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>  -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button @click="handleAdd" type="primary" icon="plus" style="margin-left:10px">复印档案</a-button> 
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <!-- <div class="table-operator">
      <a-button type="primary" @click="searchQuery" icon="search">刷新</a-button>
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> 
    </div> -->

    <!-- table区域-begin -->
    <div ref="page">
   

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:false}"
        bordered
        rowKey="id"
        
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template> 
        <span slot="hczt" slot-scope="text, record"> 
          <a @click="viewAllPic(record)" >{{ text }}</a>
        </span> 
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <!-- <a @click="handleEdit(record)">编辑</a> -->
          <a @click="handleBhyy(record)" v-if="record.zt.includes('拒绝')">查看拒绝原因</a>
          <a-divider type="vertical" v-if="record.zt.includes('拒绝')"/>
          <a @click="handleShow(record)">详情</a>
          <a-divider type="vertical" v-if="record.zt  == '待审核'"/>
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)" v-if="record.zt  == '待审核'">
            <a>删除</a>
          </a-popconfirm>
          <a-divider type="vertical" v-if="record.zt == '审核通过' || record.zt == '复审核通过'"/>
          <a @click="generatePDF(record)"  v-if="record.zt == '审核通过' || record.zt == '复审核通过'">打印预览</a> 
          <a-divider type="vertical" v-if="record.zt == '审核通过' || record.zt == '复审核通过'"/>
          <a @click="backpic(record)"  v-if="record.zt == '审核通过' || record.zt == '复审核通过'">回传</a> 
        </span>

      </a-table>
    </div>  
    <da-jyxx ref="modalForm"></da-jyxx>
    <da-jyxx-form ref="realForm" @ok="modalFormOk"></da-jyxx-form>
    <Wj-Upload ref="WjUpload" @ok="loadData"></Wj-Upload> 
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import DaJyxxModal from './modules/DaJyxxModal'
  import DaSqRyxxList from './modules/DaList'
  import DaJyxxForm from './modules/DaJyxxForm'
  import DaJyxx from './modules/DaJyxx'
  import store from '@/store/'
  import { httpAction, getAction,deleteAction } from '@/api/manage' 
  import Watermark from '@/utils/watermark'
  import WjUpload from './modules/WjUpload.vue'
  import VueViewer from 'v-viewer'
  import Vue from 'vue'
  // 全局配置
  VueViewer.setDefaults({
    zIndex: 9999, // 图片查看器的层级
    navbar: true, // 隐藏导航栏
    keyboard:true,
    toolbar: {
      zoomIn: true,
      zoomOut: true,
      oneToOne: true,
      reset: true,
      prev:true,
      next:true,
      play: true,
      rotateLeft: true,
      rotateRight: true,
      flipHorizontal: true,
      flipVertical: true,
       
    },
  })
  Vue.use(VueViewer)
  export default {
    name: 'DaJyxxList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      DaJyxxModal,
      DaSqRyxxList,
      DaJyxxForm,
      DaJyxx,
      WjUpload
    },
    data () {
      return {
        description: '复印调档表管理页面',
        // 表头
        columns: [ 
          
         
          {
            title:'姓名',
            align:"center", 
            dataIndex: 'bjyrxm',
          },
          {
            title:'身份证号',
            align:"center", 
            dataIndex: 'bjyrsfzh',
          },
          {
            title:'入伍时间',
            align:"center", 
            dataIndex: 'bjyrrwsj',
          },
          {
            title:'退伍时间',
            align:"center", 
            dataIndex: 'bjyrtwsj',
          },
          {
            title:'联系电话',
            align:"center", 
            dataIndex: 'bjyrlxdh',
          },
          {
            title:'申请原因',
            align:"center", 
            dataIndex: 'sqyy',
          },
          {
            title:'操作类型',
            align:"center", 
            dataIndex: 'czlx_dictText',
          },
          {
            title:'申请时间',
            align:"center", 
            dataIndex: 'createTime',
          },
          {
            title:'复印状态',
            align:"center",
            dataIndex: 'zt'
          },
          {
            title:'回传状态',
            align:"center",
            dataIndex: 'hczt',
            scopedSlots: { customRender: 'hczt' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          hclist:"/dajy/daJyxx/hcwjlist",
          list: "/dajy/daJyxx/list?czlx=1",
          delete: "/dajy/daJyxx/delete",
          deleteBatch: "/dajy/daJyxx/deleteBatch",
          exportXlsUrl: "/dajy/daJyxx/exportXls",
          importExcelUrl: "dajy/daJyxx/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
        showImageViewer:false,
        srcList:[],
      }
    },
    created() {
      this.getSuperFieldList();
      setTimeout(() => {
        Watermark.set(store.getters.water , this.$refs.page)
        
      }, 1000);
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: { 
      viewAllPic(e){
        console.log(e);
        this.srcList = []
        if (this.dataSource.length > 0){ 
          this.loading = true
          getAction(this.url.hclist+'?id='+e.id).then((res) => {
            console.log("申回传",res )
            if (res.code == '0') {
              res.data.forEach(item => {
                this.srcList.push(item.wjdz);
              }); 
              console.log(this.srcList)
              this.$viewerApi({
                images: this.srcList,
              })
              this.showImageViewer = true;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
            this.loading = false;
          })
        }
      },
      backpic(record){
        this.$refs.WjUpload.show(record.id);
      },
      generatePDF(record){
        window.open(record.pdf, '_blank');
      },
      handleBhyy(record){
        console.log(record)
        let bhyy = record.bhyy;
        if (bhyy == null || bhyy == '' || bhyy == undefined){
          this.$message.error("无驳回原因！");
          return;
        }
        this.$confirm({
          title: '驳回原因',
          content: bhyy,
          onOk() {
            console.log('OK');
          },

          onCancel() {
            console.log('Cancel');
          },
          class: 'test',
        });
      },
      handleShow(record){
        this.$nextTick(()=>{
          this.$refs.modalForm.show(record.id);
        })
      },
      modalFormOk(){
        this.loadData();
        console.log('返回刷新');
      },
      handleAdd(){
        this.$nextTick(()=>{
          this.$refs.realForm.show();
        })
      },
      initDictConfig(){
        
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'czlx',text:'操作类型',dictCode:'czlx'})
        fieldList.push({type:'string',value:'jyr',text:'借阅人'})
        fieldList.push({type:'string',value:'zt',text:'状态'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>